package com.hsd.mapper;

import com.hsd.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ICategoryMapper {

    /**
     * 查询父分类信息
     * @return
     */
    @Results( id = "CategoryResults",value = {
            @Result(id = true,property = "id",column = "c_id"),
            @Result(property = "name",column = "c_name"),
            @Result(property = "parent",column = "c_parent"),
            @Result(property = "tag",column = "c_tag"),
            @Result(property = "link",column = "c_link")
    })
    @Select("select * from t_category where c_parent is null")
    List<Category> selectAllFu();


    /**
     * 通过父分类来查询子分类信息
     * @param parent
     * @return
     */
    @ResultMap("CategoryResults")
    @Select("select * from t_category where c_parent=#{parent}")
    List<Category> selectByPTCh(Integer parent);

    /**
     * 插入分类信息
     * @param category
     * @return
     */
    @Insert("insert into t_category (c_name,c_parent,c_tag,c_link) values (#{name},#{parent},#{tag},#{link})")
    int addCategory(Category category);


    /**
     * 通过编号删除分类信息
     * @param id
     * @return
     */
    @Delete("delete from t_category where c_id=#{id}")
    int deleteCategory(Integer id);

    /**
     * 通过编号修改分类信息
     * @param category
     * @return
     */
    int updateCategory(Category category);
}
